const app = new Vue({
    el:"#app",
    data:{
        books:[
            {
                id:1,
                name:"计算机网络",
                price: 10,
                num:0
            },
            {
                id:2,
                name:"J2EE",
                price: 11,
                num:0
            },
            {
                id:3,
                name:"计算机组成原理",
                price: 12,
                num:0
            },
            {
                id:4,
                name:"计算机基础",
                price: 13,
                num:0
            }
        ],
        total:0,
    },
    methods:{
        increment(index){
            this.books[index].num++
        },
        decrement(index){
            this.books[index].num--
        },
        removeOne(index){
            this.books.splice(index,1);
        }
    },
    computed: {
        getTotal(){
            let all = 0;
            for(var i=0;i<this.books.length;i++){
                all+=this.books[i].price*this.books[i].num;
            }
                return all;
            }
    },

    //过滤器：返回特定格式的数据展示
    filters:{
        showPrice(price){
            return '￥'+price.toFixed(2)
        }
    }

})